package com.px.auditRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.px.auditRecord.domain.AuditRecordUser;
import com.px.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.enums.BusinessType;
import com.px.auditRecord.domain.ForRecordUser;
import com.px.auditRecord.service.IForRecordUserService;
import com.px.common.utils.poi.ExcelUtil;
import com.px.common.core.page.TableDataInfo;

/**
 * 备案详情Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("备案详情")
@RestController
@RequestMapping("/forRecord/user")
public class ForRecordUserController extends BaseController
{
    @Autowired
    private IForRecordUserService forRecordUserService;

    /**
     * 查询备案详情列表
     */
    @ApiOperation("查询备案详情列表")
    @PreAuthorize("@ss.hasPermi('forRecord:user:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(ForRecordUser forRecordUser)
    {
        startPage();
        List<ForRecordUser> list = forRecordUserService.selectForRecordUserList(forRecordUser);
        return getDataTable(list);
    }

    /**
     * 导出备案详情列表
     */
    @ApiOperation("导出备案详情列表")
    @PreAuthorize("@ss.hasPermi('forRecord:user:query')")
    @Log(title = "备案详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter(outEncode = false)
    public void export(HttpServletResponse response, ForRecordUser forRecordUser)
    {
        List<ForRecordUser> list = forRecordUserService.selectForRecordUserList(forRecordUser);
        ExcelUtil<ForRecordUser> util = new ExcelUtil<ForRecordUser>(ForRecordUser.class);
        util.exportExcel(response, list, "备案详情数据");
    }

    /**
     * 获取备案详情详细信息
     */
    @ApiOperation("获取备案详情详细信息")
    @PreAuthorize("@ss.hasPermi('forRecord:user:query')")
    @GetMapping(value = "/{id}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(forRecordUserService.selectForRecordUserById(id));
    }

    /**
     * 新增备案详情
     */
    @ApiOperation("新增备案详情")
    @PreAuthorize("@ss.hasPermi('forRecord:user:edit')")
    @Log(title = "备案详情", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody ForRecordUser forRecordUser)
    {
        return toAjax(forRecordUserService.insertForRecordUser(forRecordUser));
    }

    /**
     * 修改备案详情
     */
    @ApiOperation("修改备案详情")
    @PreAuthorize("@ss.hasPermi('forRecord:user:edit')")
    @Log(title = "备案详情", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody ForRecordUser forRecordUser)
    {
        return toAjax(forRecordUserService.updateForRecordUser(forRecordUser));
    }

    /**
     * 删除备案详情
     */
    @ApiOperation("删除备案详情")
    @PreAuthorize("@ss.hasPermi('forRecord:user:remove')")
    @Log(title = "备案详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(forRecordUserService.deleteForRecordUserByIds(ids));
    }

    /**
     * 获取个人备案详情详细信息
     */
    @ApiOperation("获取备案详情详细信息")
    @GetMapping(value = "/getForInfo")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo()
    {
        return success(forRecordUserService.selectForRecordUserByUserId(getUserId().intValue()));
    }

    @ApiOperation("根据身份证查手机号")
    @GetMapping("/getPhoneByIdCard")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getPhoneByIdCard(String IdCard)
    {
        ForRecordUser forRecordUser = forRecordUserService.selectForRecordUserByIdcard(IdCard);
        if(StringUtils.isNull(forRecordUser))
            return error("该身份证没有审核通过记录");
        AjaxResult ajax = AjaxResult.success();
        ajax.put("phonenumber", forRecordUser.getPhonenumber());
        return ajax;
    }

    @ApiOperation("账号绑定")
    @GetMapping("/forBinding")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult forBinding(AuditRecordUser auditRecordUser)
    {
        return toAjax(forRecordUserService.forBinding(auditRecordUser));
    }
}
